package biz.impl;

import java.util.List;

import biz.OrderBiz;
import dao.OrderDao;
import dao.OrderDetailDao;
import dao.impl.JDBCTemplate;
import dao.impl.OrderDaoImpl;
import dao.impl.OrderDetailDaoImpl;
import entity.Order;

public class OrderBizImpl implements OrderBiz {
	private OrderDao orderDao = new OrderDaoImpl();
	private OrderDetailDao orderDetailDao = new OrderDetailDaoImpl();
	private JDBCTemplate jdbc = new JDBCTemplate();
	@Override
	public void addOrder(Order order) {
		orderDao.addOrder(order);
	}

	@Override
	public void updateOrder(Order order) {
		orderDao.updateOrder(order);
	}

	@Override
	public List<Order> queryAllOrder() {
		List<Order> orderList = orderDao.queryAllOrder();
		for (Order order : orderList) {
			order.setOrderDetail(orderDetailDao.queryOrderDetailByOrderParentId(order.getOrderParentId()));
		}
		return orderList;
	}

	public static void main(String[] args) {
		OrderBizImpl imp = new OrderBizImpl();
		List<Order> list = imp.queryAllOrder();
		for (Order order : list) {
			System.out.println(order.getAddress().getCompleteAddress());
		}
	}
	
	@Override
	public List<Order> queryAllOrderByPaging(int pageNum, int pageSize) {
		List<Order> orderList = orderDao.queryAllOrder();
		for (Order order : orderList) {
			order.setOrderDetail(orderDetailDao.queryOrderDetailByOrderParentId(order.getOrderParentId()));
		}
		
		return jdbc.queryByPaging(orderList, pageNum, pageSize);
	}
}
